package com.ruoyi.web.controller.personnel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.domain.TeachingAchievement;
import com.ruoyi.personnel.service.ITeachingAchievementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 教学成果Controller
 *
 * @author ruoyi
 * @date 2021-03-03
 */
@Api("教学成果")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/teaching/achievement" )
public class TeachingAchievementController extends BaseController {

    private final ITeachingAchievementService iTeachingAchievementService;

    /**
     * 查询教学成果列表
     */
    @ApiOperation("查询教学成果列表")
    @PreAuthorize("@ss.hasPermi('teaching:achievement:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingAchievement teachingAchievement) {
        startPage();
        List<TeachingAchievement> list = iTeachingAchievementService.queryList(teachingAchievement);
        return getDataTable(list);
    }

    /**
     * 导出教学成果列表
     */
    @ApiOperation("导出教学成果列表")
    @PreAuthorize("@ss.hasPermi('teaching:achievement:export')" )
    @Log(title = "教学成果" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TeachingAchievement teachingAchievement) {
        List<TeachingAchievement> list = iTeachingAchievementService.queryList(teachingAchievement);
        ExcelUtil<TeachingAchievement> util = new ExcelUtil<TeachingAchievement>(TeachingAchievement.class);
        return util.exportExcel(list, "achievement" );
    }

    /**
     * 获取教学成果详细信息
     */
    @ApiOperation("获取教学成果详细信息")
    @PreAuthorize("@ss.hasPermi('teaching:achievement:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(iTeachingAchievementService.getById(id));
    }

    /**
     * 新增教学成果
     */
    @ApiOperation("新增教学成果")
    @PreAuthorize("@ss.hasPermi('teaching:achievement:add')" )
    @Log(title = "教学成果" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingAchievement teachingAchievement) {
        teachingAchievement.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iTeachingAchievementService.save(teachingAchievement) ? 1 : 0);
    }

    /**
     * 修改教学成果
     */
    @ApiOperation("修改教学成果")
    @PreAuthorize("@ss.hasPermi('teaching:achievement:edit')" )
    @Log(title = "教学成果" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingAchievement teachingAchievement) {
        return toAjax(iTeachingAchievementService.updateById(teachingAchievement) ? 1 : 0);
    }

    /**
     * 删除教学成果
     */
    @ApiOperation("删除教学成果")
    @PreAuthorize("@ss.hasPermi('teaching:achievement:remove')" )
    @Log(title = "教学成果" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(iTeachingAchievementService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
